﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;

namespace CAION2.ViewModels
{
    public abstract class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    
    public class SampleCollection<T> : INotifyPropertyChanged, IEnumerable
    {
        private readonly List<T> list = new List<T>();
        public event PropertyChangedEventHandler PropertyChanged;
        
        public T this[int i]
        {
            get { return list[i]; }

            set
            {
                list[i] = value;
                
                OnPropertyChanged("Item[]");
            }
        }

        public void Add(T value)
        {
            list.Add(value);
        }

        public List<T> FindAll(Predicate<T> match)
        {
            return list.FindAll(match);
        }

        public bool All(Predicate<T> match)
        {
            return list.TrueForAll(match);
        }

        public T Find(Predicate<T> match)
        {
            return list.Find(match);
        }

        private void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public IEnumerator GetEnumerator()
        {
            return list.GetEnumerator();
        }

        
    }
    
}
